package com.db.williamchart.renderer.executor;

import com.db.williamchart.data.DataPoint;
import com.db.williamchart.data.Frame;

import java.util.ArrayList;
import java.util.List;

public class GetVerticalBarBackgroundFrames {

    public List<Frame> invoke(Frame innerFrame, Float spacingBetweenBars, List<DataPoint> data){
        float halfBarWidth = (innerFrame.getRight() - innerFrame.getLeft() - (data.size() + 1) * spacingBetweenBars) /
                data.size() / 2;
        List<Frame> frames = new ArrayList<>();
        for (DataPoint dataPoint : data){
            frames.add(new Frame(dataPoint.getScreenPositionX() - halfBarWidth,innerFrame.getTop(),dataPoint.getScreenPositionX() + halfBarWidth ,innerFrame.getBottom()));
        }
        return frames;
    }
}
